<template>
  <div id="GoodsList-item" @click="itemClick">
    <!-- v-on:load事件可以监听图片加载是否完成，完成后调动回调函数 -->
    <img :src="goodsItem.show.img" alt="" @load="imageLoad"/>
    <div class="GoodsList-item-info">
      <p>{{goodsItem.title}}</p>
      <span class="price">{{goodsItem.price}}</span>
      <span class="collect">{{goodsItem.cfav}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "GoodsList-item",
  data() {
    return {};
  },
  methods: {
    imageLoad(){
       this.$bus.$emit("itemImageLoad")

      // this.$root.$emit("itemImageLoad")
    },

    // 跳转商品详情页
    itemClick(){
      console.log("跳转")
      this.$router.push("/detail/"+this.goodsItem.iid);
    }
  },
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
};
</script>

<style scoped>
#GoodsList-item {
    padding-bottom: 40px;
    position: relative;
    width: 45%;
    
    
    
  }
  #GoodsList-item img {
    width: 100%;
  }

  .GoodsList-item-info {
    font-size: 12px;
    position: absolute;
    bottom: 5px;
    left: 0;
    right: 0;
    overflow: hidden;
    text-align: center;
  }

  .GoodsList-item-info p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }

  .GoodsList-item-info .price {
    color: var(--color-high-text);
    margin-right: 20px;
  }

  .GoodsList-item-info .collect {
    position: relative;
  }

  .GoodsList-item-info .collect::before {
    content: '';
    position: absolute;
    left: -15px;
    top: 0;
    width: 14px;
    height: 14px;
    background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
  }
</style>